package com.lzx.applib.utils;

import android.content.Context;
import android.widget.Toast;

/**
 * Created by Lzx on 16/10/20 0020.
 */

public class ToastUtil {

    private static final String TAG = "ToastUtil";

    private static Toast toast;

    public synchronized static void init(Context context) {
        if (toast == null) {
            toast = Toast.makeText(context.getApplicationContext(), "", Toast.LENGTH_SHORT);
        }
        init = true;
    }

    public static ToastUtil instance = new ToastUtil();
    private static boolean init = false;

    public static ToastUtil getInstance() {
        if (!init) {
            throw new IllegalStateException("Toast should be inited befor used.");
        }
        return instance;
    }

    public void toast(Object object) {
        String text = null;
        if (object == null) {
            return;
        }
        if (object instanceof Integer) {
            toast.setText((Integer) object);
        } else {
            toast.setText(object.toString());
        }
        toast.show();
    }
}
